// Copyright [2020] <Weaverzhu>
#include <bits/stdc++.h>
using namespace std;
// #define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
#define dbg(x...) { cerr << "\033[32;1m" << #x << " -> "; err(x); }
void err() { cerr << "\033[39;0m" << endl; }
template<typename T, typename... A>
void err(T a, A... x) { cerr << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

#define sz(x) ((int)x.size())

const int N = 1e3+50;
const int INF = 0x3f3f3f3f;
int dp[N][N][2];
int n, k;
int a[N], p[N];
vector<int> pos[N];

int disc(int a[], int n)
{
    static int disc[N], dcnt;
    dcnt = 0;
    for (int i=0; i<n; ++i)
        disc[dcnt++] = a[i];
    sort(disc, disc + dcnt);
    dcnt = unique(disc, disc + dcnt) - disc;
    for (int i=0; i<n; ++i)
        a[i] = lower_bound(disc, disc + dcnt, a[i]) - disc;
    return dcnt;
}


inline void update(int &a, int b)
{
    a = min(a, b);
}
int main(int argc, char const *argv[]) {
    // code
    int t; cin >> t;
    for (int kk=0; kk<t; ++kk) {
        scanf("%d%d", &n, &k);
        for (int i=0; i<n; ++i)
            scanf("%d", &p[i]);
        for (int i=0; i<n; ++i)
            scanf("%d", &a[i]);
        int m = disc(a, n);
        for (int i=0; i<m; ++i) {
            pos[i].clear();
        }
        for (int i=0; i<n; ++i) {
            pos[a[i]].push_back(p[i]);
        }
        for (int i=0; i<m; ++i)
            sort(pos[i].begin(), pos[i].end());

        for (int i=0; i<m; ++i)
            for (int j=0; j<=k; ++j)
                dp[i][j][0] = dp[i][j][1] = INF;
        dp[0][0][0] = dp[0][0][1] = 0;
        for (int i=0; i<sz(pos[0]); ++i) {
            dp[0][i+1][0] = 2 * pos[0][i];
            dp[0][i+1][1] = pos[0][i];
        }
        for (int i=1; i<m; ++i)
            for (int j=0; j<=k; ++j)
            {
                int mi = INF;
                dp[i][j][0] = dp[i-1][j][0];
                for (int k=0; k<sz(pos[i]) && j-k-1>=0; ++k)
                    mi = min(mi, dp[i-1][j-k-1][0] + 2 * pos[i][k]);
                update(dp[i][j][0], mi);
                mi = INF;
                dp[i][j][1] = min(dp[i-1][j][0], dp[i-1][j][1]);
                for (int k=0; k<sz(pos[i]) && j-k-1>=0; ++k)
                    mi = min(mi, min(dp[i-1][j-k-1][1] + 2 * pos[i][k], dp[i-1][j-k-1][0] + pos[i][k]));
                update(dp[i][j][1], mi);
            }
        // dbg(dp[0][0][0]);
        int ans = dp[m-1][k][1];
        printf("Case #%d: %d\n", kk+1, ans);
    }
    return 0;
}
